<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>输入评审</title>
    <link rel="stylesheet" href="/lims/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lims/css/eleTree.css">
    <script src="/lims/layui/layui.js"></script>
    <script type="text/javascript" src="/lims/layui/global.js"></script>
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lims/js/common.js?v=20190726" type="text/javascript" charset="utf-8"></script>
    <style>
        #deptName td {
            padding: 0 10px 0 10px;
        }
        layui-nav-item {
            position: absolute;
            left: 5px;
            top: 23px;
            z-index: 9999999;
        }
        .layui-table-view .layui-table td, .layui-table-view .layui-table th {
            padding: 3px 0;
        }
        .layui-tab-item {
            height: 100%;
        }
        .layui-tab-item iframe{
            width: 100%;
            height:100%;
        }
    </style>
</head>
<body>
<div class="layui-card" style="margin:0;width: 100%;height: 100%;padding: 0;position: fixed;">
    <div class="layui-tab layui-tab-brief" lay-filter="edittabbar" style="height: 100%;">
        <h2 class="layui-colla-title">委托单<span id="orders"></span></h2>
        <ul class="layui-tab-title">
            <li class="layui-this" id="a"><span style="font-size: 16px">基本信息</span></li>
            <li><span style="font-size: 16px">产品/试验信息</span></li>
            <li><span style="font-size: 16px">附件</span></li>
        </ul>
        <div class="layui-tab-content" style="position:relative;overflow:hidden;padding: 0;height: 100%;">
            <div class="layui-tab-item layui-show">
                <%--<iframe id="basicInfourl" style="width: 100%;height:100%;" frameborder="no"--%>
                <%--src="/project_input/basicInfo?deptId=17&amp;begin=edit&amp;projectId=2"></iframe>--%>
                <iframe id="basicInfoUrl" frameborder="no" src=""></iframe>
            </div>
            <div class="layui-tab-item">
                <iframe id="productInfoUrl" frameborder="no" src=""></iframe>
            </div>
            <div class="layui-tab-item">
                <iframe id="proappendixUrl" frameborder="no" src=""></iframe>
            </div>
        </div>
    </div>
</div>

<div id="temple" style="display:none;">
    <div style="width:80%;margin: 0 auto;">
        <p style="margin-top: 10px;">从组织架构中读取标记为“独立实验室”的组织</p>
        <table id="demo" lay-filter="test"></table>
    </div>
</div>

<script type="text/javascript">
    var getChild;
    var getChildData;
    var flag = 0;
    var customerName;//客户名称
    var customerId;//客户ID

    var runId=window.parent.runId;//获取 父页面 地址栏 参数 runId
    var projectId='';
    var deptId='';

    layui.use(['table', 'layer', 'form', 'element'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var element = layui.element;
        var $ = layui.jquery;

        //试验室
        var laboratory=table.render({
            elem: '#demo'
            ,data:[]
            ,page: false //开启分页
            ,cols: [[ //表头
                {type: 'radio'}
                ,{field: 'deptName', title: '试验室'}
            ]]
        });

        // 判断是否需要选择实验室
        $.ajax({
            url: '/workapp/work/selectProjectByRunId?runId='+runId,
            type: 'post',
            dataType: 'json',
            success: function (res) {
                // 已选择实验室
                if(res.code== 0){
                    projectId=res.object.projectId; //立项已经生成，后台返回立项Id
                    deptId=res.object.projectId;
                    $("#basicInfoUrl").attr("src", '/project_input/basicInfo?projectId='+projectId+'&deptId='+deptId+'&begin=edit');
                    $('#orders').text(res.object.projectNo)//立项已经生成，后台返回立项编号
                }

                // 未选择实验室
                if (res.code!= 0) {
                    layer.open({
                        type: 1,
                        title:'请选择要下单的实验室',
                        area: ['25%', '60%'],
                        maxmin: true,
                        btn: ['确定', '取消'],
                        content: $('#temple'),
                        success: function (res) {
                            laboratory.reload({
                                url:'/EquipBorrow/Laboratory'
                            });
                        },
                        yes: function (index, layero) {
                            var checkStatus = table.checkStatus('demo'); //获取选中行
                            if(checkStatus.data.length>0){
                                layer.close(index);//关闭窗口
                                var deptId= checkStatus.data[0].deptId;  //获取选中行数据
                                $.ajax({
                                    url: '/project_input/addingItems',
                                    type: 'get',
                                    dataType: 'json',
                                    data:{
                                        deptId:deptId,
                                        runId:runId
                                    },
                                    success: function (res) {
                                        layer.msg(res.msg)
                                        projectId=res.object.projectId; //立项已经生成，后台返回立项Id
                                        deptId=res.object.projectId;
                                        $("#basicInfoUrl").attr("src", '/project_input/basicInfo?projectId='+projectId+'&deptId='+deptId+'&begin=edit');
                                        $('#orders').text(res.object.projectNo)//立项已经生成，后台返回立项编号
                                    }
                                });
                            }else{
                                layer.msg("请选中某个实验室");
                            }
                        }
                    })
                }
            }
        });

        element.on('tab(edittabbar)', function (data) {
            var index = data.index;
            switch (index) {
                case 1:
                    if (flag == 0) {
                        layer.msg('请保存"基本信息"后，再继续');
                        $("#a").click();
                        return false;
                    } else {
                        // if (customerName == undefined) {
                        //     var searchUrl = '/project_input/productInfo?projectId=' + rowData.projectId + '&customerName=' + escape(rowData.customerName) + '&customerId=' + escape(rowData.customerId) + '&deptId=' + rowData.deptId + '&begin=edit';
                        // } else {
                        //     var searchUrl = '/project_input/productInfo?projectId=' + rowData.projectId + '&customerName=' + escape(customerName) + '&customerId=' + escape(customerId) + '&deptId=' + rowData.deptId + '&begin=edit';
                        // }
                        // src = searchUrl;

                        var productInfoUrl='/project_input/productInfo?projectId='+projectId+'&customerName='+escape(customerName)+'&customerId='+customerId+'&deptId='+deptId+'&begin=edit'
                        $("#productInfoUrl").attr("src", productInfoUrl);
                    }
                    break;
                case 2:
                    if (flag == 0) {
                        layer.msg('请保存"基本信息"后，再继续');
                        $("#a").click();
                        return false;
                    } else {
                        // var searchUrl = '/project_input/proappendix?projectId=' + rowData.projectId + '&deptId=' + rowData.deptId + '&begin=edit';
                        // src = searchUrl;

                        var proappendixUrl='/project_input/proappendix?projectId='+projectId+'&deptId='+deptId+'&begin=edit'
                        $("#proappendixUrl").attr("src", proappendixUrl);
                    }
                    break;
            }
        })
    })

    // 获取子页面的数据方法
    getChild = function (saveflag) {
        flag = saveflag;
    }

    //获取子页面的数据方法
    getChildData = function (data) {
        customerName = data[0].customerName;
        customerId = data[0].customerId;
    }

    setTimeout(function () {
        customerName=$("#basicInfoUrl").contents().find("#customerName").val();//客戶名称
        customerId=$("#basicInfoUrl").contents().find("#customerId").attr('name');//客户id

        $("#productInfoUrl").contents().find("#customerName").val(customerName);//产品/试验信息 页面 客戶名称
    },1000)
</script>
</body>
</html>